<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>重置账号和密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <!-- <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">-->
    <link rel="icon" th:href="@{/读书1.jpg}" type="image/jpg" >
    <link rel="stylesheet" th:href="@{/admin.css}" media="all">
    <link rel="stylesheet" th:href="@{/login.css}" media="all">
    <link rel="stylesheet" th:href="@{/layui-v2.5.7/layui/css/layui.css}">
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script th:src="@{/layui-v2.5.7/layui/layui.js}"></script>
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>重置密码和账号</h2>
            <p>交流社区</p>
        </div>

        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
                <input type="text" name="nickname" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="重置账号" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="password" placeholder="重置密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" ></label>
                <input type="text" name="email" id="LAY-user-login-cellemail" lay-verify="email" placeholder="你的邮箱" class="layui-input">
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit" id="reset_button">重置</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <a th:href="@{/login}" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
                <a href="" class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">
            <p>© 2021 <a href="http://www.xc.com/" target="_blank">cx.com</a></p>
            <p></p>
        </div>

    </div>
</div>

</body>
<script>
    $(function () {
        $("#reset_button").click(function () {

            layui.use('layer', function () {

            	//用户名验证:必须由字母，数字下划线组成，并且长度为5到12位
                var usernameText = $("#LAY-user-login-nickname").val();
                //创建正则表达式对象
                var usernamePatt = /^\w{5,12}$/;
                //使用test方法验证
                if (!usernamePatt.test(usernameText)) {
                    layer.msg("用户名称为5到12位个字符！");
                    return false;
                }

                //密码验证:必须由字母，数字下划线组成，并且长度为5到12位
                var passwordText = $("#LAY-user-login-password").val();
                //创建正则表达式对象
                var passwordPatt = /^\w{5,12}$/;
                //使用test方法验证
                if (!passwordPatt.test(passwordText)) {
                    layer.msg("密码名称为5到12位个字符！");
                    return false;
                }

                //确认密码：和密码相同
                var repasswordTest = $("#LAY-user-login-repass").val();
                //和密码相比较
                if (repasswordTest != passwordText) {
                    layer.msg("两次密码不一致！");
                    return false;
                }

                //邮箱格式验证：
	            var emailText = $("#LAY-user-login-cellemail").val();
	            //创建正则表达式对象
	            var emailPatt = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
	            //使用test方法验证是否合法
                if (!emailPatt.test(emailText)) {
                    layer.msg("邮箱格式不正确");
                    return false;
                }

                $.ajax({
    	        	url:"/ImagineCommunity/resetPassword",
    	        	type:"post",
    	        	data:{username:usernameText,
    				      password:passwordText,
    	        		  email:emailText,
    	        	},
                    success: function (res) {
                    console.log(res.registerSuccess);
                        if(res.userByEmail == 'no'){
                            layer.msg(res.msg);
                        }
                        if(res.resetPasswordSuccess == 'yes'){
                            layer.msg("发送成功,快去邮箱点击重置密码吧!");
                            setTimeout(function(){
                                window.location.href = "/ImagineCommunity/login";
                            },2000)

                        }
                    }
    			})
    			return false;
            })
        })
   })

</script>
</html>